package com.mxsat.system.service.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mxsat.common.enums.dict.DataStatusEnum;
import com.mxsat.system.dao.SysUserDao;
import com.mxsat.system.entity.SysUser;
import com.mxsat.system.service.SysUserService;

@Service
public class SysUserServiceImpl implements SysUserService {

	@Autowired
	private SysUserDao sysUserDao;
	
	@Override
	public SysUser findUserForLoginByName(String name, String pwd) throws Exception {
		return sysUserDao.selectUserByNameAndPwd(name, pwd);
	}

	@Override
	public IPage<SysUser> findSysUsersByPage(IPage<SysUser> page,Map<String, Object> condition) throws Exception {
		return sysUserDao.selectUserByPage(page, condition);
	}

	@Override
	public SysUser findSysUserById(Long id) throws Exception {
		return sysUserDao.getById(id);
	}

	@Override
	public SysUser findUserByName(String name) throws Exception {
		return sysUserDao.selectUserByName(name);
	}

	@Override
	public boolean addSysUser(SysUser user) throws Exception {
		user.setData_status(DataStatusEnum.正常.toCode());
		user.setPwd(user.getName());
		return sysUserDao.save(user);
	}

	@Override
	public boolean modifySysUserById(SysUser user) throws Exception {
		return sysUserDao.updateById(user);
	}

	@Override
	public boolean removeSysUserById(Long id) throws Exception {
		return sysUserDao.removeById(id);
	}

}
